package problem844;

//844.比较含退格的字符串
//https://leetcode.cn/problems/backspace-string-compare/description/

class Solution {
    public boolean backspaceCompare(String s, String t) {
        return change(s).equals(change(t));
    }
    public String change(String s) {
        StringBuffer ret = new StringBuffer();
        for(char ch : s.toCharArray()) {
            if(ch != '#') {
                ret.append(ch);
            }else if(ret.length() > 0){
                ret.deleteCharAt(ret.length()-1);
            }
        }
        System.out.println(ret);
        return ret.toString();
    }
}